home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk5 / shell210 / shell.doc < prev    next >
Text File  |  1995-03-18  |  21KB  |  695 lines

  1.  
  2. SHELL V2.10  (C)Copyright 1986-88, Matthew Dillon, All Rights Reserved.
  3. Freely distributable for non-profit only.
  4.  
  5.  
  6.         PLEASE READ THE VERSION HISTORY AT THE BOTTOM FOR
  7.         CHANGES FROM 2.07.    Also, re-read the overview just below.
  8.  
  9.  
  10.       (A)   Compiling
  11.       (B)   Overview
  12.       (C)   Quicky tech notes on implimentation.
  13.  
  14.       (D)   Command pre-processor
  15.       (E)   Command-list
  16.       (F)   special SET variables
  17.       (G)   Version history
  18.  
  19.        See also EXAMPLES.TXT
  20.  
  21.  
  22.                 COMPILATION
  23.  
  24.  
  25.     The SHELL will compile only under AZTEC C and requires my
  26.     support library (SUP32.LIB) to link as well as a precompiled
  27.     symbol table of all AMIGA .H files.  A Makefile is included.
  28.     Note that the shell must be compiled using 32 bit integers (+L)
  29.     option and linked with SUP32.LIB and C32.LIB.
  30.  
  31.     NOTE that converting the shell to use 16 bit integers does not
  32.     make it significantly smaller or faster.  Do not waste your time.
  33.  
  34.  
  35.  
  36.                  OVERVIEW
  37.  
  38.  
  39.     Matthew Dillon
  40.     891 Regal Rd.
  41.     Berkeley, California 94708
  42.     USA
  43.  
  44.     ..!ucbvax!dillon
  45.     dillon@ucbvax.Berkeley.EDU
  46.     dillon@cory.Berkeley.EDU
  47.  
  48.     This is not a shareware program.  My basic philosophy is to write
  49.     software for myself and distribute it if I think it will benefit
  50.     others (that is, unless I start going broke).  Contribute if you want
  51.     to.
  52.  
  53.     IT IS SUGGESTED THAT YOU USE CONMAN OR THE NEW 1.3 ENHANCED CONSOLE
  54.     DEVICE.  CONMAN does to my shell what Steve did in his Manxfied (old
  55.     term) 16 bit version of my shell, and more.  It isn't required, but
  56.     CONMAN (shareware) complements the functionality of the shell quite
  57.     well.
  58.  
  59.  
  60.    PROBLEMS
  61.  
  62.    -Make sure you give the SHELL a big enough stack, especially if you
  63.     intend on running shell scripts which source other scripts.  8192
  64.     is suggested.  Remember, STACK must be run BEFORE you run the shell.
  65.     Running it from the shell does not effect the shell's stack.
  66.  
  67.    -You should not redirect the RUN command. to redirect the command the
  68.     RUN command is running, embed a standard CLI redirection in the command
  69.     string:
  70.  
  71.     RUN ">file" command
  72.  
  73.    -Append '>>' does NOT work with BCPL programs.  It does work with all
  74.     internal and non-bcpl (read C) programs.
  75.  
  76.    OVERVIEW of the major features:
  77.  
  78.    -History mechanism (complements conman quite nicely, in fact)
  79.    -Redirection
  80.    -Piping (sort of)
  81.    -Command search path by name and by CLI path list
  82.    -Aliases
  83.    -Variables & variable handling (embedded variables), and enviroment variables
  84.    -Automatic file name expansion via '?' and '*'
  85.    -Conditionals
  86.    -Shell Scripts
  87.    -many built in commands to speed things up
  88.  
  89.  
  90.                 COMMAND PREPROCESSOR
  91.  
  92.  
  93.    preprocessing is done on the command line before it is passed on to
  94.    an internal or external routine:
  95.  
  96.    ^c        where c is a character is converted to that control character.
  97.         Thus, say '^l' for control-l.
  98.  
  99.    $name    where name is a variable name.  Variable names can consist of
  100.         0-9, a-z, A-Z, and underscore (_).  The contents of the
  101.         specified variable is used.  If the variable doesn't exist,
  102.         the specifier is used.  That is, if the variable 'i' contains
  103.         'charlie', then '$i' -> 'charlie'.  If the variable 'i' doesn't
  104.         exist, then '$i'->'$i' .
  105.  
  106.    ;        delimits commands.     echo charlie ; echo ben.
  107.  
  108.    ' '      (a space). Spaces delimit arguments.
  109.  
  110.    "string" a quoted string.  For instance, if you want to echo five spaces
  111.         and an 'a':
  112.  
  113.         echo      a       -> a
  114.         echo "    a"      ->      a
  115.  
  116.    \c        overide the meaning of special characters.    '\^a' is a
  117.         circumflex and an a rather than control-a.    To get a backslash,
  118.         you must say '\\'.
  119.  
  120.         also used to overide alias searching for commands.
  121.  
  122.    >file    specify output redirection.  All output from the command is
  123.         placed in the specified file.
  124.  
  125.    >>file   specify append redirection (Does not work with BCPL programs).
  126.  
  127.    <file    specify input redirection.    The command takes input from the
  128.         file rather than the keyboard (note: not all commands require
  129.         input).  It makes no sense to say  'echo <charlie' since
  130.         the 'echo' command only outputs its arguments.
  131.  
  132.    |        PIPE specifier.  The output from the command on the left becomes
  133.         the input to the command on the right.  The current SHELL
  134.         implimentation uses temporary files to store the data.
  135.  
  136.    !!        execute the previously executed command.
  137.    !nn        (nn is a number).  Insert the history command numbered n (see
  138.         the HISTORY command)
  139.    !partial search backwards through the history list for a command which
  140.         looks the same as 'partial', and execute it.
  141.  
  142.    #        Enter comment.  The rest of the line is discarded (note: \#
  143.         will, of course, overide the comment character's special
  144.         meaning)
  145.  
  146.    ^search^replace
  147.         a '^' at the beginning of the line indicates history
  148.         replacement.  The first occurance of 'search' in the previous
  149.         command is changed to 'replace', and the command executed.
  150.  
  151.  
  152.  
  153.                  SHELL COMMANDS
  154.  
  155.  
  156.    The first argument is the command-name... if it doesn't exist in the
  157.    list below and isn't an alias, it is assumed to be an external (disk)
  158.    command.
  159.  
  160.    AUTOMATIC SOURCING may be accomplished by naming shell scripts with a
  161.    .sh suffix.    Thus, if you say 'stuff' and the file 'stuff.sh' exists in
  162.    your current or C: directory, it will be SOURCED with any arguments you
  163.    have placed in the $_passed variable.
  164.  
  165.               EXCEPTION_PROCESSING
  166.  
  167.       if no _except variable exists, any command which fails causes the
  168.       rest of the line to abort as if an ABORTLINE had been executed.  If
  169.       the _except variable exists, it is of the form:
  170.  
  171.       "nnn;commands..."
  172.  
  173.       where nnn is some value representing the minimum return code required
  174.       to cause an error.  Whenever a command returns a code which is
  175.       larger or equal to nnn, the commands in _except are executed before
  176.       anything.  WHEN _except EXISTS, THE COMMAND LINE DOES NOT ABORT
  177.       AUTOMATICALLY.  Thus, if you want the current line being executed
  178.       to be aborted, the last command in _except should be an "abortline".
  179.  
  180.       exception handling is disabled while in the exception handling routine
  181.       (thus you can't get into any infinite loops this way).
  182.  
  183.       Thus if _except = ";", return codes are completely ignored.
  184.  
  185.       example:
  186.  
  187.       set _except "20;abortline"
  188.  
  189.  
  190.    ABORTLINE
  191.  
  192.       or just 'abort'.  Causes the rest of the line to be aborted. Used in
  193.       conjunction with exception handling.
  194.  
  195.       % echo a;abort;echo b
  196.       a
  197.  
  198.  
  199.    HELP
  200.  
  201.       simply displays all the available commands.  The commands are
  202.       displayed in search-order.  That is, if you give a partial name
  203.       the first command that matches that name in this list is the one
  204.       executed.  Generally, you should specify enough of a command so that
  205.       it is completely unique.
  206.  
  207.    QUIT
  208.    EXIT
  209.    RETURN [n]
  210.  
  211.       quit my SHELL (awww!).  End, El-Zappo, Kapow. Done, Finis.  If you
  212.       use RETURN and are on the top source level, the shell exits with the
  213.       optional return code.  (see RETURN below)
  214.  
  215.  
  216.    SET
  217.    SET name
  218.    SET name string
  219.  
  220.       The first method lists all current variable settings.
  221.       The second method lists the setting for that particular variable,
  222.       or creates the variable if it doesn't exist (to "")
  223.       The last method sets a variable to a string.
  224.  
  225.       see the section on special _ variables down below
  226.  
  227.  
  228.    UNSET name name name....
  229.  
  230.       unset one or more variables.  Deletes them entirely.
  231.  
  232.  
  233.    SETENV name string
  234.  
  235.       Create/Modify an enviroment variable.  The enviroment is maintained
  236.       in ENV:, with a separate file for each enviroment variable.  This
  237.       should be assigned to a directory somewhere.
  238.  
  239.    UNSETENV name name name....
  240.  
  241.       remove the specified variables from the enviroment list.    This
  242.       call DeleteFile()'s the enviroment variable from ENV:
  243.  
  244.    PRINTENV
  245.  
  246.       Print the contents of the enviroment directory ENV:
  247.  
  248.    ALIAS
  249.    ALIAS name
  250.    ALIAS name string
  251.  
  252.       same as SET, but applies to the alias list.  You can alias a single
  253.       name to a set of commands.  For instance:
  254.  
  255.       alias hi "echo a; echo b"
  256.  
  257.       then you can simply say 'hi'.  Aliases come in two forms the second
  258.       form allows you to place the arguments after an alias in a variable
  259.       for retrieval:
  260.  
  261.       alias xxx "%i echo this $i is a test"
  262.  
  263.       % xxx charlie
  264.       this charlie is a test
  265.  
  266.       The rest of the command line is placed in the specified variable
  267.       for the duration of the alias.  This is especially useful when used
  268.       in conjunction with the 'FOREACH' command.
  269.  
  270.  
  271.    UNALIAS name name name...
  272.  
  273.       delete aliases..
  274.  
  275.  
  276.    ECHO string
  277.    ECHO -n string
  278.  
  279.       echo the string to the screen.  If '-n' is specified, no newline is
  280.       output.
  281.  
  282.  
  283.    STRHEAD  varname breakchar string
  284.  
  285.       remove everything after and including the breakchar in 'string' and
  286.       place in variable 'varname':
  287.  
  288.      % strhead j . aaa.bbb
  289.      % echo $j
  290.      aaa
  291.      %
  292.  
  293.  
  294.    STRTAIL  varname breakchar string
  295.  
  296.       remove everything before and including the breakchar in 'string' and
  297.       place in variable 'varname':
  298.  
  299.      % strtail j . aaa.bbb
  300.      % echo $j
  301.      bbb
  302.      %
  303.  
  304.  
  305.    SOURCE file [arguments]
  306.  
  307.       execute commands from a file.  You can create SHELL programs in
  308.       a file and then execute them with this command.  Source'd files
  309.       have the added advantage that you can have loops in your command
  310.       files (see GOTO and LABEL).  You can pass SOURCE files arguments
  311.       by specifying arguments after the file name.  Arguments are passed
  312.       via the _passed variable (as a single string).
  313.  
  314.       Automatic 'sourcing' is accomplished by placing a .sh extension on
  315.       the file and executing it as you would a C program:
  316.  
  317.       --------- file hello.sh ---------
  318.       foreach i ( $_passed ) "echo yo $i"
  319.       ---------------------------------
  320.       % hello a b c
  321.       yo a
  322.       yo b
  323.       yo c
  324.  
  325.       NOTE: The hash '#' as the FIRST character on the line is a comment
  326.         within script files.
  327.  
  328.    MV from to
  329.    MV from from from ... from todir
  330.  
  331.       Allows you to rename a file or move it around within a disk.  Allows
  332.       you to move 1 or more files into a single directory.  (if todir == '/',
  333.       the items are moved to the parent directory).
  334.  
  335.    CD
  336.    CD ..
  337.    CD path
  338.  
  339.       Change your current working directory.  You may specify '..' to go
  340.       back one directory (this is a CD specific feature, and does not
  341.       work with normal path specifications).  Note that CD / also goes
  342.       back one directory.
  343.  
  344.       CD without any arguments displays the path of the directory you
  345.       are currently in.
  346.  
  347.  
  348.    PWD
  349.       rebuild _cwd by backtracing from your current directory.    The $_cwd
  350.       variable can get confused by Assign'd labels.
  351.  
  352.    RM [-r] file file file...
  353.  
  354.       DeleteFile().  Remove the specified files.  Remove always returns
  355.       errorcode 0.  You can remove empty directories.  The '-r' option
  356.       will remove non-empty directories by recursively removing all sub
  357.       directories.
  358.  
  359.    CP file    (to current directory)
  360.    CP [-r] dir    (to current directory)
  361.    CP file file
  362.    CP file1 file2...fileN dir
  363.    CP [-r] dir1 dir2...dirN dir
  364.  
  365.       copy files or directories.  when copying directories, the "-r" option
  366.       must be specified to copy subdirectories as well.  Otherwise, only
  367.       top level files in the source directory are copied.
  368.  
  369.  
  370.    MKDIR name name name...
  371.  
  372.       create the following directories.
  373.  
  374.  
  375.    HISTORY [partial_string]
  376.  
  377.       Displays the enumerated history list.  The size of the list is
  378.       controlled by the _history variable.  If you specify a partial-
  379.       string, only those entries matching that string are displayed.
  380.  
  381.  
  382.    MEM
  383.  
  384.       Display current memory statistics for CHIP and FAST memory.
  385.  
  386.  
  387.    CAT [file file....]
  388.  
  389.       Type the specified files onto the screen.  If no file is specified,
  390.       STDIN in used.  CAT is meant to output text files only.  You cannot
  391.       use CAT to join binaries together.
  392.  
  393.    DIR [-s] [path path ... ]
  394.  
  395.       Get a directory listing of the current directory or specified
  396.       directories.  The -s option causes DIR to display a short-form
  397.       listing.
  398.  
  399.    DEVINFO [device: device:... ]
  400.  
  401.       Display Device statistics for the current device (CD base), or
  402.       specified devices.
  403.  
  404.  
  405.    FOREACH varname ( strings ) command
  406.  
  407.       'strings' is broken up into arguments.  Each argument is placed in
  408.       the variable 'varname' in turn and 'command' executed.  To execute
  409.       multiple commands, place them in quotes:
  410.  
  411.       % foreach i ( a b c d ) "echo -n $i;echo \" ha\""
  412.       a ha
  413.       b ha
  414.       c ha
  415.       d ha
  416.  
  417.       Foreach is especially useful when interpreting passed arguments in
  418.       an alias or source file.
  419.  
  420.       NOTE: a GOTO inside a FOREACH will have an indeterminate effect.
  421.  
  422.  
  423.    FOREVER command
  424.    FOREVER "command;command;command..."
  425.  
  426.       The specified commands are executed over and over again forever.
  427.  
  428.       -Execution stops if you hit ^C
  429.       -If the commands return with an error code.
  430.  
  431.       NOTE: a GOTO inside will have an indeterminate effect.
  432.  
  433.  
  434.    RETURN [value]
  435.  
  436.       return from a source file.  The rest of the source file is
  437.       discarded.  If given, the value becomes the return value for the
  438.       SOURCE command.  If you are on the top level, this value is returned
  439.       as the exit code for the shell.
  440.  
  441.  
  442.    IF -f path
  443.    IF argument conditional argument ;
  444.    IF argument
  445.  
  446.       If a single argument is something to another argument.  Conditional
  447.       clauses allowed:
  448.  
  449.       <, >, =, and combinations (wire or).  Thus <> is not-equal, >=
  450.       larger or equal, etc...
  451.  
  452.       If the left argument is numeric, both arguments are treated as
  453.       numeric.
  454.  
  455.       usually the argument is either a constant or a variable ($varname).
  456.  
  457.       The third form if IF is conditional on the existance of the argument.
  458.       If the argument is a "" string, then FALSE , else TRUE.
  459.  
  460.       The first form is TRUE if the path can be openned with modes 1005.
  461.  
  462.  
  463.    ELSE ;
  464.  
  465.       else clause.
  466.  
  467.  
  468.    ENDIF ;
  469.  
  470.       the end of an if statement.
  471.  
  472.  
  473.    LABEL name
  474.  
  475.       create a program label right here.  You can only have labels within
  476.       a source file.
  477.  
  478.  
  479.    GOTO label
  480.  
  481.       goto the specified label name.  You can only use this command from a
  482.       source file.
  483.  
  484.  
  485.    DEC var
  486.    INC var
  487.  
  488.       decrement or increment the numerical equivalent of the variable and
  489.       place the ascii-string result back into that variable.
  490.  
  491.  
  492.    INPUT varname
  493.  
  494.       input from STDIN (or a redirection, or a pipe) to a variable.  The
  495.       next input line is placed in the variable.
  496.  
  497.  
  498.    VER
  499.  
  500.       display my name, the version number, and the version date.
  501.  
  502.  
  503.    SLEEP timeout
  504.  
  505.       Sleep for 'timeout' seconds.
  506.  
  507.  
  508.  
  509.               SPECIAL VARIABLES
  510.  
  511.  
  512.    _prompt
  513.      This variable is set to the command you wish executed that will
  514.      create your prompt.
  515.  
  516.    _history
  517.      This variable is set to a numerical value, and specifies how far
  518.      back your history should extend.
  519.  
  520.    _histnum
  521.      This variable contains the history # of the next command that
  522.      will be executed.
  523.  
  524.    _debug
  525.      Debug mode... use it if you dare.  must be set to some value
  526.  
  527.    _verbose
  528.      Verbose mode (for source files).  display commands as they are
  529.      executed.
  530.  
  531.    _maxerr
  532.      The worst (highest) return value to date.  To use this, you usually
  533.      set it to '0', then do some set of commands, then check it.
  534.  
  535.    _lasterr
  536.      Return code of last command executed.    This includes internal
  537.      commands as well as external comands, so to use this variables
  538.      you must check it IMMEDIATELY after the command in question.
  539.  
  540.    _cwd
  541.      Holds a string representing the current directory we are in from
  542.      root.    The SHELL can get confused as to its current directory if
  543.      some external program changes the directory.  Use PWD to rebuild
  544.      the _cwd variable in these cases.
  545.  
  546.    _passed
  547.      This variable contains the passed arguments when you SOURCE a file
  548.      or execute a .sh file.  For instance:
  549.  
  550.      test a b c d
  551.  
  552.      -------- file test.sh ----------
  553.      echo $_passed
  554.      foreach i ( $_passed ) "echo YO $i"
  555.      --------------------------------
  556.  
  557.  
  558.    _path
  559.      This variable contains the search path when the shell is looking
  560.      for external commands.  The format is:  DIR,DIR,DIR  Each DIR must
  561.      have a trailing ':' or '/'.  The current directory is always
  562.      searched first.  The entire path will be searched first for the
  563.      <command>, then for <command>.sh (automatic shell script sourcing).
  564.  
  565.      The default _path is set to  "c:,ram:,ram:c/,df1:c/,df0:c/"
  566.  
  567.      NOTE:    The CLI path is also searched.
  568.  
  569.     _ignoreeof
  570.      If this variable exists, EOF is ignored on interactive
  571.      terminals.  This prevents accidental logouts.
  572.  
  573.     _copysilent
  574.      If this variable exists, the CP command will be silent.  The
  575.      default is now for CP to be verbose.
  576.  
  577.     _copydate
  578.     If this variables exists, the CP command will attempt to
  579.     transfer the datestamp src->dst file/dir.  For directories,
  580.     only those that CP must create will get the old datestamp
  581.     transfered to them.  Additionaly, the COMMENT, if any, will
  582.     the transfered src->dst file/dir.
  583.  
  584.  
  585.  
  586.                 TECH NOTES
  587.  
  588.  
  589.  
  590.    PIPES have been implimented using temporary RAM: files.  Thus, you
  591.    should be careful when specifying a 'ram:*' expansion as it might
  592.    include the temp. files.  These files are deleted on completion of
  593.    the pipe segment.
  594.  
  595.    The file names used are completely unique, even with multiple shells
  596.    running simultaniously.
  597.  
  598.    My favorite new feature is the fact that you can now redirect to and
  599.    from, and pipe internal commands.  'echo charlie >ram:x', for
  600.    instance.  Another favorite:
  601.  
  602.       echo "echo mem | shell" | shell
  603.  
  604.    To accomplish these new features, I completely re-wrote the command
  605.    parser in execom.c
  606.  
  607.    The BCPL 'RUN' command should not be redirected.. .strange things
  608.    happen.  You can use redirection WITHIN the RUN's command line, of
  609.    course, but it should be quoted so the shell doesn't think the
  610.    redirection is for it.
  611.  
  612.    NO BCPL program should be output-append redirected (>>).
  613.  
  614.  
  615.  
  616.                  VERSION HISTORY
  617.  
  618.  
  619.     V2.10:
  620.     -Command dispatch has been fixed... RUN used to create problems
  621.      sometimes (would give you a CLI prompt when it should not have).
  622.  
  623.     -MV fixed ... had problems when moving things to the current
  624.      directory ("") and names starting with '/'.
  625.  
  626.     -SETENV, PRINTENV commands added.  $var variables search the
  627.      enviroment (ENV:).  Aliases are searched for in ENV: as well
  628.      now.
  629.  
  630.      This allows you to have global variables and aliases for all
  631.      the shells running in the system without having to resource an
  632.      initialization file.  Additionaly, to the limits of the command
  633.      line, the contents of any file in ENV: may be inserted by
  634.      referencing it as a variable.
  635.  
  636.      ANY system variable may be placed in the enviroment instead of
  637.      the local variables if you wish.
  638.  
  639.     -DIR enhanced.    Defaults to long list format.
  640.  
  641.     V2.08:
  642.  
  643.     -WaitForChar() removed from main processing loop (the old Delay(0)
  644.      bug though in this case it is WaitForChar(x,1).
  645.  
  646.     -CP now accepts single parameters (ala MSDOS).. copy a file or
  647.      directory to the current directory (-r for recursive sub-dirs)
  648.         CP FILE
  649.         CP [-r] DIR
  650.  
  651.     -A new variable, _copydate, which, if it exits, causes CP to
  652.      transfer both the comment and datestamp of the source to the
  653.      destination.
  654.  
  655.         set _copydate
  656.  
  657.     V2.07:  (Internal)
  658.  
  659.     V2.06B:
  660.     -External programs that change the current directory are caught,
  661.      and no longer crash the machine.
  662.  
  663.     -CP command, the _copysilent variable, if it exists, causes
  664.      directory and recursive copies to do their work in silence.
  665.  
  666.     V2.06:
  667.     -IF enhanced.  -f option added.  (if -f path).  If the named path
  668.      can be openned with modes 1005, then...
  669.  
  670.     -various routines fixed.
  671.  
  672.     V2.04:
  673.     - CP command now internal... see instructions.
  674.     - RM command now has '-r' option.
  675.     - \command forces the command parser NOT to look at aliases.  Thus,
  676.        you can alias something like 'cd' and have the alias contain a 'cd'
  677.        which references the internal cd:
  678.  
  679.        alias cd "stuff...;\\cd $x"
  680.  
  681.     - "-c" command line option to execute commands and return.
  682.  
  683.        shell -c "echo a;echo b;echo c".
  684.  
  685.     - _path default now places RAM: and RAM:C first rather than last.
  686.     - _histnum variable .. current history #
  687.     - expanded filenames are sorted.
  688.     - ^search^replace (modify previous command).
  689.  
  690.     V2.03 AND BELOW
  691.  
  692.     Before Written History (actually not quite, but there was this
  693.     fire you see....)
  694.  
  695.